package guggaTests.utils
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import flexunit.framework.TestCase;
	
	import gugga.eventHelpers.EventRethrower;

	public class EventRethrowerTest extends TestCase
	{
		private var mEventDispatched : Boolean = false; 
		
		public function EventRethrowerTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public function testRethrowEvent() : void
		{
			var eventDispatcher1 : EventDispatcher = new EventDispatcher;
			var eventDispatcher2 : EventDispatcher = new EventDispatcher;
			var eventDispatcher3 : EventDispatcher = new EventDispatcher;
			
			var eventRethrower : EventRethrower;
			
			eventRethrower = EventRethrower.create(eventDispatcher2, eventDispatcher1, "TestEvent");
			
			eventDispatcher2.addEventListener("TestEvent", eventFunction);
			
			eventDispatcher1.dispatchEvent(new Event("TestEvent"));
			
			assertTrue(
				"Event have to be dispatched but it wasn't",
				mEventDispatched
				);
			mEventDispatched = false;
			
			eventDispatcher2 = null;
			
			eventDispatcher1.dispatchEvent(new Event("TestEvent"));
			
			assertTrue(
				"Event have to be dispatched but it wasn't",
				mEventDispatched
				);
			mEventDispatched = false;
			
			eventDispatcher2 = new EventDispatcher;
			
			eventDispatcher3.dispatchEvent(new Event("TestEvent"));
			
			assertFalse(
				"Event have not to be dispatched but it wasn't",
				mEventDispatched
				);
			mEventDispatched = false;


				
		}
		
		private function eventFunction(aEvent : Event) : void
		{
			mEventDispatched = true;
		}
			
		
		
	}
}